#include<bits/stdc++.h>
#define int long long
using namespace std;
const int Maxn = 1010;
int n, ans;
int vis[Maxn];
int a[Maxn], b[Maxn];
map<vector<int>, int> mp;
queue<int> c, d;
void dfs(int x, int cnt1, int cnt2){
	if(x > 2 * n - 2){
		while(!c.empty()) c.pop();
		while(!d.empty()) d.pop();
		vector<int> s;
		for(int i = 1 ; i <= n ; i++){
			c.push(a[i]);
			d.push(b[i]);
		}
		for(int i = 1 ; i <= 2 * n - 2 ; i++){
			if(vis[i] == 1){
				s.push_back(d.front());
				c.pop();
			}else{
				s.push_back(c.front());
				d.pop();
			}
		}
		if(!mp[s]) ans++;
		mp[s] = 1;
		return ;
	}
	if(cnt1 < n - 1){
		vis[x] = 1;
		dfs(x + 1, cnt1 + 1, cnt2);
	} 
	if(cnt2 < n - 1){
		vis[x] = 2;
		dfs(x + 1, cnt1, cnt2 + 1);
	}
}
signed main(){
	ios::sync_with_stdio(false);
	freopen("zha.in", "r", stdin);
	freopen("zha.out", "w", stdout);
	cin >> n;
	for(int i = 1 ; i <= n ; i++) cin >> a[i];
	for(int i = 1 ; i <= n ; i++) cin >> b[i];
	dfs(1, 0, 0);
	cout << ans << '\n';
	return 0;
}